package my.jwds.p2100;

import java.util.*;

public class GoodDaysToRobBank {
    public static void main(String[] args) {
        GoodDaysToRobBank obj = new GoodDaysToRobBank();
        int [] security = {4,3,2,1};
        int time = 1;
        System.out.println(obj.goodDaysToRobBank(security,time));
    }


    public List<Integer> goodDaysToRobBank(int[] security, int time) {
        int l = security.length;
        Deque<Integer> stack1 = new ArrayDeque<>();
        Deque<Integer> stack2 = new ArrayDeque<>();
        boolean[]flags = new boolean[l];
        Arrays.fill(flags,true);
        for (int i = 0; i < l; i++) {
            if (!stack1.isEmpty() ){
                if (security[stack1.peek()] < security[i]){
                    stack1.clear();
                }
                flags[i] = flags[i] && stack1.size() >= time;
            }else{
                flags[i] = time == 0;
            }
            stack1.push(i);
            if(!stack2.isEmpty() ){

                if (security[stack2.peek()] < security[l-i-1]){
                    stack2.clear();
                }
                flags[l-i-1] = flags[l-i-1] && stack2.size() >= time;
            }else{
                flags[l-i-1] = time == 0;
            }

            stack2.push(l-i-1);
        }
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < flags.length; i++) {
            if (flags[i]) res.add(i);
        }
        return res;
    }
}